// 上传控制器
define('uploaderController', ['angular'], function (angular) {
    var module = angular.module('controllers');
    module.controller('uploaderController', ['$scope','$http','$rootScope','Urlconfig','businessServers',function ($scope,$http,$rootScope,Urlconfig,businessServers) {
        $scope.uploadExcl = function(){   
            var fd = new FormData();
            var file = document.querySelector('input[type=file]').files[0];
            fd.append('excl', file);
            $scope.uploadState=true;
            $http({
                method:'POST',
                url:'http://'+Urlconfig.apiUrl+':8888/api/uploader/Excl',
                data: fd,
                headers: {'Content-Type':undefined},
                transformRequest: angular.identity}
            ).then(function (response){
                if(response.data!==false){
                    $scope.data=response.data;
                    alert("上传成功");
                    $scope.uploadState=false;
                }else{
                    $scope.data='';
                    $scope.uploadState=false;
                    alert("该文件格式不符合");
                }
                //上传成功的操作
                // alert("uplaod success");
            });
        };
        $scope.clientBatchSave=function(){
            var companyid=$rootScope.user.company;
            for(var i=0;i<$scope.data.length;i++){
                $scope.data[i].business_type=1;
            }
            // console.log($scope.data);
            var dataStr=JSON.stringify($scope.data);
            businessServers.addMultitermBusiness(dataStr,companyid).then(function(data) {
                if(data){
                    alert("添加成功");
                }else{
                    alert("添加失败");
                }
            });
            console.log($scope.dataStr);
        };
    }]);
});